#  Copyright 2012 the original author or authors.
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

__author__ = 'Adrian CITU'

import xml.sax
import dffshellgenerator.xmlConstants as const

class tagHandler(xml.sax.handler.ContentHandler):

    def __init__(self):
        self.file = None
        self.filenameTag = False
        self.commandTag = False
        self.commandNameTag = False
        self.commandArgumentTag = False
        self.argumentNameTag = False
        self.argumentValueTag = False
        self.dffScriptTag = False

    def startElement(self, name, attr):
        name = name.encode('ascii')

        if name == const.xmlConstants.XML_FILENAME_TAG :
            self.filenameTag = True
        if name == const.xmlConstants.XML_COMMAND_NAME_TAG :
            self.commandNameTag = True
            self.filenameTag = False


    def endElement(self, name):
        name = name.encode('ascii')

        if name == const.xmlConstants.XML_DFFSCRIPT_TAG :
            self.file.close()

    def characters(self, content):
        if self.filenameTag == True :
            self.file = open(content,'w')
        if self.file is not None and self.filenameTag == False:
            self.file.writelines(content)

    def setBoolFieldToTrue(self, attributeName):
        print ""